<<<<<<< HEAD
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Guarantee extends CI_Controller {
	
	private $tab = 'borrow';
	function __construct(){
		parent::__construct();
		/** 登陆验证 */
		if(!isset($_SESSION)){
		    session_start();
		}
		
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /sys_admin/login');
			exit;
		}
	}
	
	function add_view(){
		
		$this->load->model('Attestation_type_model', 'attestation_type');
		$data['type_list'] = $this->attestation_type->get_id_names();
		
		$data['sub'] = 'guarantee_add';
		$data['tab'] = $this->tab;
		
		$this->load->view("/sys_admin/borrow/guarantee_add",$data);
	}
	
	function add(){  		
  		$data['name'] 		= $this->input->post('name');
  		$data['account'] 		= $this->input->post('account');
  		$data['province'] 	= $this->input->post('province');
  		$data['city'] 	= $this->input->post('city');
  		$data['address'] 		= $this->input->post('address');
  		$data['contact'] 		= $this->input->post('contact');
  		$data['web'] 		= $this->input->post('web');
  		$data['establishment_time'] 	= strtotime($this->input->post('establishment_time'));
  		$data['collaboration_time'] 		= strtotime($this->input->post('collaboration_time'));
  		$data['introduction'] 		= $this->input->post('introduction');
  		
  		$this->load->model('borrow_model');
  		
  		$act = $this->input->post('act');
  		if($act == 'add'){
  			$guarantee_id = $this->borrow_model->guarantee_add($data);
  		}else{
  			$id		= $this->input->post('id');
  			$res = $this->borrow_model->guarantee_update($id,$data);
  			$guarantee_id = $id;
  		}
  		
  		
  		if($guarantee_id>0){
  			$this->load->model('Attestation_model', 'attestation');
  			
  			$att_id 	= $this->input->post('att_id');
  			if(isset($att_id) && $att_id){
  				
	  			$att_ret = $this->attestation->get_list_guarantee_by_id($att_id,$guarantee_id);
	  			if($att_ret>0){
	  				$this->load->model('log_model');$this->log_model->add_log('[添加][担保机构]');
	  			}
  			}
  			header("location:/sys_admin/guarantee/guaranteelist");
	   		exit;
  		} 		
	}
	
	
	function edit_view($guarantee_id){
		$this->load->model('borrow_model');
  		$guarantee = $this->borrow_model->get_borrow_guarantee_obj($guarantee_id);
  		$this->load->model('Attestation_model', 'attestation');
  		$vdata['att_list']  = $this->attestation->get_list_guarantee($guarantee_id);
  		
  		$this->load->model('Attestation_type_model', 'attestation_type');
		$vdata['type_list'] = $this->attestation_type->get_id_names();
		
  		$vdata['guarantee'] = $guarantee;
  		$vdata['sub'] = 'guarantee_list';
  		$vdata['tab'] = $this->tab;
  		$this->load->view("/sys_admin/borrow/guarantee_edit", $vdata);
	}
	
	
	
	function guaranteelist(){			
		$this->load->model('borrow_model');
				
		$per_page  = intval($this->input->get('per_page'));
		$page_size = 10;
		
		$parms     = array(
			'name'   => trim($this->input->get('name')),
			'is_del'=>0,
		);
						
		$vdata = $this->borrow_model->get_guarantee_list($parms,$per_page,$page_size);
		
		//分页
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/links/zhs_linkslist/?name='.$parms['name'];
		$config['total_rows'] = $vdata['count'];
		$config['per_page'] = 10; 
		$this->pagination->initialize($config); 
		
		$this->load->model('Area_model', 'area');
		$vdata['area_list'] = $this->area->get_list();
		
		$vdata['name'] 	= $name;
		$vdata['sub'] = 'guarantee_list';
		$vdata['tab'] = $this->tab;
		$this->load->view('/sys_admin/borrow/guarantee_list', $vdata);
	}
	
	function remove(){
		$id 				= $this->input->post('id');
  		$data["is_del"]		= 1;
  		$this->load->model('borrow_model');
  		$this->load->model('log_model');$this->log_model->add_log('[删除][担保机构]');
		echo  $this->borrow_model->guarantee_update($id, $data);
	}
	
	
	function doupload(){
		$ret = array(
			'msg' => '',
			'url' => ''
		);
		
		$this->load->model('Attestation_model', 'attestation');
				
		$jifen = 0;
		$time = time();
		$ip = $this->input->ip_address();
		
		$this->load->model('Attestation_type_model', 'attestation_type');
		$where = array('type_id'=>$this->input->post('type_id'));
		$att_info = $this->attestation_type->get_one($where);
		
		$setArr = array(
			'user_id' => 0,
			'type_id' => $this->input->post('type_id'),
			'name'    => $att_info['name'],
			'fstatus'  => 1,
			'jifen'   => $jifen,
			'content' => $att_info['name'],
			'verify_time' => $time,
			'verify_user' => 1,
			'verify_remark' => $this->input->post('verify_remark'),
			'add_time' => $time,
			'addip' => $ip,
		);
			
		$path = 'static/data/upfiles/images/guarantee/';
		if(!file_exists($path)){
			mkdir($path,0777);
		}
		$config['upload_path'] = $path;
		$config['allowed_types'] = 'jpg|png';
		$config['file_name'] = 'attestation_'.uniqid();
		$config['overwrite'] = true;
		$config['max_size'] = '512';
		$config['max_width']  = '2048';
		$config['max_height']  = '3000';

		$this->load->library('upload', $config);
		if($this->upload->do_upload('litpic')){
			$tmp = $this->upload->data();
			$setArr['litpic'] = 'static/data/upfiles/images/guarantee/'.$config['file_name'].$tmp['file_ext'];
			
			//添加水印
			$this->load->library('image_lib');
			$warter['source_image'] = $setArr['litpic'];
			$warter['wm_type'] = 'overlay';
			$warter['wm_overlay_path'] = 'static/images/dd_logo.png';
			$warter['wm_opacity'] = '60';
			$warter['wm_vrt_alignment'] = 'middle';
			$warter['wm_hor_alignment'] = 'center';
			$this->image_lib->initialize($warter);
			$this->image_lib->watermark();
			
			$res = $this->attestation->add($setArr);
			if($res){
				$ret['msg'] = array('id'=>$res,'name'=>$setArr['name'],'litpic'=>$setArr['litpic']);
				
			}else{
				$ret['msg'] = '保存失败';
			}
			
		}else{
			$ret['url'] = 'error';
			$ret['msg'] = $this->upload->display_errors();
		}
		echo json_encode($ret);
		exit;
	}
	
	function del_att($id=''){
		$id = intval($id);
		$this->load->model('Attestation_model', 'attestation');
		$att_info = $this->attestation->get_one(array('id'=>$id));
		$res = $this->attestation->delete(array('id'=>$id,'guarantee_id'=>$att_info['guarantee_id']));
		if($res){
			$ret = array('msg'=>'删除成功','url'=>'');
			echo json_encode($ret);
			exit; 
		}else{
			$ret = array('msg'=>'删除失败','url'=>'');
			echo json_encode($ret);
			exit; 
		}
		
	}
	
	
}
=======
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Guarantee extends CI_Controller {
    
	private $tab = 'borrow';
	function __construct(){
		parent::__construct();
		/** 登陆验证 */
		if(!isset($_SESSION)){
		    session_start();
		}
		
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /sys_admin/login');
			exit;
		}
	}
	
	function add_view(){
		
		$this->load->model('Attestation_type_model', 'attestation_type');
		$data['type_list'] = $this->attestation_type->get_id_names();
		
		$data['sub'] = 'guarantee_add';
		$data['tab'] = $this->tab;
		
		$this->load->view("/sys_admin/borrow/guarantee_add",$data);
	}
	
	function add(){  		
  		$data['name'] 		= $this->input->post('name');
  		$data['account'] 		= $this->input->post('account');
  		$data['province'] 	= $this->input->post('province');
  		$data['city'] 	= $this->input->post('city');
  		$data['address'] 		= $this->input->post('address');
  		$data['contact'] 		= $this->input->post('contact');
  		$data['web'] 		= $this->input->post('web');
  		$data['establishment_time'] 	= strtotime($this->input->post('establishment_time'));
  		$data['collaboration_time'] 		= strtotime($this->input->post('collaboration_time'));
  		$data['introduction'] 		= $this->input->post('introduction');
  		
  		$this->load->model('borrow_model');
  		
  		$act = $this->input->post('act');
  		if($act == 'add'){
  			$guarantee_id = $this->borrow_model->guarantee_add($data);
  		}else{
  			$id		= $this->input->post('id');
  			$res = $this->borrow_model->guarantee_update($id,$data);
  			$guarantee_id = $id;
  		}
  		
  		
  		if($guarantee_id>0){
  			$this->load->model('Attestation_model', 'attestation');
  			
  			$att_id 	= $this->input->post('att_id');
  			if(isset($att_id) && $att_id){
  				
	  			$att_ret = $this->attestation->get_list_guarantee_by_id($att_id,$guarantee_id);
	  			if($att_ret>0){
	  				$this->load->model('log_model');$this->log_model->add_log('[添加][担保机构]');
	  			}
  			}
  			header("location:/sys_admin/guarantee/guaranteelist");
	   		exit;
  		} 		
	}
	
	
	function edit_view($guarantee_id){
		$this->load->model('borrow_model');
  		$guarantee = $this->borrow_model->get_borrow_guarantee_obj($guarantee_id);
  		$this->load->model('Attestation_model', 'attestation');
  		$vdata['att_list']  = $this->attestation->get_list_guarantee($guarantee_id);
  		
  		$this->load->model('Attestation_type_model', 'attestation_type');
		$vdata['type_list'] = $this->attestation_type->get_id_names();
		
  		$vdata['guarantee'] = $guarantee;
  		$vdata['sub'] = 'guarantee_list';
  		$vdata['tab'] = $this->tab;
  		$this->load->view("/sys_admin/borrow/guarantee_edit", $vdata);
	}
	
	
	
	function guaranteelist(){			
		$this->load->model('borrow_model');
				
		$per_page  = intval($this->input->get('per_page'));
		$page_size = 10;
		
		$parms     = array(
			'name'   => trim($this->input->get('name')),
			'is_del'=>0,
		);
						
		$vdata = $this->borrow_model->get_guarantee_list($parms,$per_page,$page_size);
		
		//分页
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/links/zhs_linkslist/?name='.$parms['name'];
		$config['total_rows'] = $vdata['count'];
		$config['per_page'] = 10; 
		$this->pagination->initialize($config); 
		
		$this->load->model('Area_model', 'area');
		$vdata['area_list'] = $this->area->get_list();
		
		$vdata['name'] 	= $name;
		$vdata['sub'] = 'guarantee_list';
		$vdata['tab'] = $this->tab;
		$this->load->view('/sys_admin/borrow/guarantee_list', $vdata);
	}
	
	function remove(){
		$id 				= $this->input->post('id');
  		$data["is_del"]		= 1;
  		$this->load->model('borrow_model');
  		$this->load->model('log_model');$this->log_model->add_log('[删除][担保机构]');
		echo  $this->borrow_model->guarantee_update($id, $data);
	}
	
	
	function doupload(){
		$ret = array(
			'msg' => '',
			'url' => ''
		);
		
		$this->load->model('Attestation_model', 'attestation');
				
		$jifen = 0;
		$time = time();
		$ip = $this->input->ip_address();
		
		$this->load->model('Attestation_type_model', 'attestation_type');
		$where = array('type_id'=>$this->input->post('type_id'));
		$att_info = $this->attestation_type->get_one($where);
		
		$setArr = array(
			'user_id' => 0,
			'type_id' => $this->input->post('type_id'),
			'name'    => $att_info['name'],
			'fstatus'  => 1,
			'jifen'   => $jifen,
			'content' => $att_info['name'],
			'verify_time' => $time,
			'verify_user' => 1,
			'verify_remark' => $this->input->post('verify_remark'),
			'add_time' => $time,
			'addip' => $ip,
		);
			
		$path = 'static/data/upfiles/images/guarantee/';
		if(!file_exists($path)){
			mkdir($path,0777);
		}
		$config['upload_path'] = $path;
		$config['allowed_types'] = 'jpg|png';
		$config['file_name'] = 'attestation_'.uniqid();
		$config['overwrite'] = true;
		$config['max_size'] = '512';
		$config['max_width']  = '2048';
		$config['max_height']  = '3000';

		$this->load->library('upload', $config);
		if($this->upload->do_upload('litpic')){
			$tmp = $this->upload->data();
			$setArr['litpic'] = 'static/data/upfiles/images/guarantee/'.$config['file_name'].$tmp['file_ext'];
			
			//添加水印
			$this->load->library('image_lib');
			$warter['source_image'] = $setArr['litpic'];
			$warter['wm_type'] = 'overlay';
			$warter['wm_overlay_path'] = 'static/images/dd_logo.png';
			$warter['wm_opacity'] = '60';
			$warter['wm_vrt_alignment'] = 'middle';
			$warter['wm_hor_alignment'] = 'center';
			$this->image_lib->initialize($warter);
			$this->image_lib->watermark();
			
			$res = $this->attestation->add($setArr);
			if($res){
				$ret['msg'] = array('id'=>$res,'name'=>$setArr['name'],'litpic'=>$setArr['litpic']);
				
			}else{
				$ret['msg'] = '保存失败';
			}
			
		}else{
			$ret['url'] = 'error';
			$ret['msg'] = $this->upload->display_errors();
		}
		echo json_encode($ret);
		exit;
	}
	
	function del_att($id=''){
		$id = intval($id);
		$this->load->model('Attestation_model', 'attestation');
		$att_info = $this->attestation->get_one(array('id'=>$id));
		$res = $this->attestation->delete(array('id'=>$id,'guarantee_id'=>$att_info['guarantee_id']));
		if($res){
			$ret = array('msg'=>'删除成功','url'=>'');
			echo json_encode($ret);
			exit; 
		}else{
			$ret = array('msg'=>'删除失败','url'=>'');
			echo json_encode($ret);
			exit; 
		}
		
	}
	
	
}
>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
